<script>
	// <!--
		
	$(function(){
		/* external function */
		
		$.fn.serializeObject = function()
		{
		   var o = {};
		   var a = this.serializeArray();
		   $.each(a, function() {
			   if (o[this.name]) {
				   if (!o[this.name].push) {
					   o[this.name] = [o[this.name]];
				   }
				   o[this.name].push(this.value || '');
			   } else {
				   o[this.name] = this.value || '';
			   }
		   });
		   return o;
		};
		
		/* declarisasi */
		txtubahpassword = $("#txt-ubahpassword");
		txtubahpasswordrepeat = $("#txt-ubahpasswordrepeat");
		btnSimpanubahpassword = $("#btn-simpanubahpassword");
		formubahpassword = $("#form-ubahpassword");
		tabs_settings = $("#tabs_settings");
		
		btnsave_setting = $("#btnsave_setting");
		/* event */
		btnSimpanubahpassword.click(function(){
			
			passwordNew = txtubahpassword.val();
			passwordRepeat = txtubahpasswordrepeat.val();
			if (passwordNew == ""){
				alert("Password tidak boleh kosong!");
			}else if(passwordNew != passwordRepeat){
				alert("Password tidak sama!");
			}else{			
				$.ajax({
					url : "c_settings",
					data : {task : "UBAH_PASSWORD",password : passwordNew},
					type : 'POST'
				}).done(function(response){
					if (response == "1"){
						alert("Password berhasil disimpan!");
					}
				});
			}
		});	
		
		btnsave_setting.click(function(){
			data = $("#form-editprofile").serializeObject();
			$.ajax({
				url : "c_settings",
				data : data,
				type : 'POST'
			}).done(function(response){
					if (response == "1"){
						alert("Password berhasil disimpan!");
					}
			});
		});
		
		/* method started */
		tabs_settings.tabs();
	});
	// -->
</script>
<div id="tabs_settings">
	<ul>
		<li><a href="#div-editprofile">Edit Profile </a></li>
		<li><a href="#div-changepassword">Change Password</a></li>
	</ul>
	<div id="div-editprofile">
		<div class="ui-widget " style="width:400px">
			<div class="ui-widget-header">
				<center>Edit Profile</center>
			</div>
			<div class="ui-widget-content">
				<form class="form-horizontal" id="form-editprofile" disabled=true  onSubmit="return false">
					<input  name="task" value="UPDATE" placeholder="0" hidden=hidden>
						<table>
							<tr>
								<td>Full Name</td>
								<td><input type="text" id="user_real_name" name="user_real_name" class="input-control" value="<?php echo @$user_real_name ;?>"></td>
							</tr>
							<tr>
								<td>User Name</td>
								<td><input type="text" id="user_name" name="user_name" class="input-control" value="<?php echo @$user_name ;?>"></td>
							</tr>
							<tr>
								<td>Email</td>
								<td><input type="text" id="user_email" name="user_email" class="input-control" value="<?php echo @$user_email ;?>"></td>
							</tr>
							<tr>
								<td></td>
								<td><button class="button" id="btnsave_setting"  onSubmit="return false"><span>Simpan</span></button></td>
							</tr>
						</table>
				</form>
			</div>
		</div>
	</div>
	<div id="div-changepassword">
		<div class="ui-widget " style="width:400px">
			<div class="ui-widget-header">
				<center>Change Your Password</center>
			</div>
			<div class="ui-widget-content">
				<form class="form-horizontal" id="form-ubahpassword" onSubmit="return false">
					<div>	
						<table>
							<tr><td><input  name="task" value="UBAH_PASSWORD" placeholder="0" hidden=hidden></td></tr>
							<tr>
								<td>New Password</td>
								<td><input type="password" id="txt-ubahpassword" name="txt-ubahpassword" class="input-control"></td>
							</tr>
							<tr>
								<td>Repeat Password</td>
								<td><input type="password" id="txt-ubahpasswordrepeat" name="txt-ubahpasswordrepeat" class="input-control"></td>
							</tr>
							<tr>
								<td></td>
								<td><button class="button" id="btn-simpanubahpassword" onSubmit="return false;"><span>Simpan</span></button></td>
							</tr>
						</table>
						</div>
				</form>
			</div>
		</div>
	</div>
</div>